package com.jobs.TreeHashDemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TreeSet;

/**
 * @author 王博
 */
public class TreeSetMain {
    public static void main(String[] args) {
        //使用自然排序
        TreeSet<Student> treeSet = new TreeSet<>();
        treeSet.add(new Student(1,18,"张三","男",true));
        treeSet.add(new Student(2,18,"李四","男",false));
        treeSet.add(new Student(3,48,"王五","女",true));
        treeSet.add(new Student(4,8,"赵六","女",true));

        treeSet.forEach(System.out::println);


        Student zhangsan = new Student(1,18,"张三","男",true);
        Student lisi = new Student(2,16,"李四","男",true);

        List<Student> list = new ArrayList<>();
        list.add(zhangsan);
        list.add(lisi);

        //使用外部排序
        list.sort(new MyComparator());

        for (Student student2 : list) {
            System.out.println(student2);
        }
    }
}
